//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Data
{
    public class QueryTableRefresh: IOfficeXmlSerializable
    {
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("queryTableRefresh"))
            {
                PreserveSortFilterLayout = c.GetOptionalBoolean("preserveSortFilterLayout", true);
                FieldIdWrapped = c.GetOptionalBoolean("fieldIdWrapped", false);
                HeadersInLastRefresh = c.GetOptionalBoolean("headersInLastRefresh", true);
                NextId = c.GetOptionalInteger("nextId", 1);
                UnboundColumnsLeft = c.GetOptionalInteger("unboundColumnsLeft", 0);
                UnboundColumnsRight = c.GetOptionalInteger("unboundColumnsRight", 0);
                MinimumVersion = c.GetOptionalInteger("minimumVersion", 0);
                Fields.Clear();
                foreach (QueryTableField f in c.ReadOptionalListElement<QueryTableField>("queryTableFields", "queryTableField"))
                    Fields.Add(f);
                DeletedFields.Clear();
                foreach (QueryTableDeletedField f in c.ReadOptionalListElement<QueryTableDeletedField>("queryTableDeletedFields", "deletedField"))
                    DeletedFields.Add(f);
                SortState = c.ReadOptionalElement<SortState>("sortState");
                Extension = c.ReadOptionalElement<ExtensionElement>("extLst");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("queryTableRefresh"))
            {
                c.SetOptionalBoolean("preserveSortFilterLayout", PreserveSortFilterLayout, true);
                c.SetOptionalBoolean("fieldIdWrapped", FieldIdWrapped, false);
                c.SetOptionalBoolean("headersInLastRefresh", HeadersInLastRefresh, true);
                c.SetOptionalInteger("nextId", NextId, 1);
                c.SetOptionalInteger("unboundColumnsLeft", UnboundColumnsLeft, 0);
                c.SetOptionalInteger("unboundColumnsRight", UnboundColumnsRight, 0);
                c.SetOptionalInteger("minimumVersion", MinimumVersion, 0);
                using (WriteContext c2 = context.Write("queryTableFields"))
                {
                    c2.SetInteger("count", Fields.Count);
                    foreach (QueryTableField f in Fields)
                        c2.WriteElement(f);
                }
                if (DeletedFields.Count > 0)
                {
                    using (WriteContext c2 = context.Write("queryTableDeletedFields"))
                    {
                        c2.SetInteger("count", DeletedFields.Count);
                        c2.WriteElements(DeletedFields);
                    }
                }
                c.WriteOptionalElement(SortState);
                c.WriteOptionalElement(Extension);
            }
        }

        #endregion

        private ExtensionElement _extension;

        public ExtensionElement Extension
        {
            get { return _extension; }
            set { _extension = value; }
        }
	

        private List<QueryTableField> _fields = new List<QueryTableField>();

        public List<QueryTableField> Fields
        {
            get { return _fields; }
            set { _fields = value; }
        }
        private List<QueryTableDeletedField> _deletedFields = new List<QueryTableDeletedField>();

        public List<QueryTableDeletedField> DeletedFields
        {
            get { return _deletedFields; }
            set { _deletedFields = value; }
        }
        private SortState _sortState;

        public SortState SortState
        {
            get { return _sortState; }
            set { _sortState = value; }
        }
        private bool _preserveSortFilterLayout = true;

        public bool PreserveSortFilterLayout
        {
            get { return _preserveSortFilterLayout; }
            set { _preserveSortFilterLayout = value; }
        }
        private bool _fieldIdWrapped;

        public bool FieldIdWrapped
        {
            get { return _fieldIdWrapped; }
            set { _fieldIdWrapped = value; }
        }
        private bool _headersInLastRefresh;

        public bool HeadersInLastRefresh
        {
            get { return _headersInLastRefresh; }
            set { _headersInLastRefresh = value; }
        }
        private int _minimumVersion;

        public int MinimumVersion
        {
            get { return _minimumVersion; }
            set { _minimumVersion = value; }
        }
        private int _nextId = 1;

        public int NextId
        {
            get { return _nextId; }
            set { _nextId = value; }
        }
        private int _unboundColumnsLeft;

        public int UnboundColumnsLeft
        {
            get { return _unboundColumnsLeft; }
            set { _unboundColumnsLeft = value; }
        }
        private int _unboundColumnsRight;

        public int UnboundColumnsRight
        {
            get { return _unboundColumnsRight; }
            set { _unboundColumnsRight = value; }
        }
	
	
	
	
	
	
	
	
	
    }
}
